Hi
Some code here, pushing values on a stack untill it finds an operator, and then does (it should) the operation. The first part pushing the values is working fine. Then, when it doesn't find a digit anymore and executes the switch arguments, it does something, for me, strange. When I output the values it recieves, instead operators (in ascii) it recieves letters, starting with several 'A's. I'm pretty sure to handle the casting/pointer for the switch input wrong, but nevertheless I can't explain the values, where they came from and why that many?
--> given the input: exp 2 3 *
Code:
int main(int argc, char *argv[])
{
int n;
double op2;
while (--argc > 0) {
if (isdigit(n = **++argv))
push(atof(*argv)); //
else {
switch (n) {
case '+':
push(pop() + pop());
break;
case '*':
push(pop() * pop());
break;
case '-':
op2 = pop();
push(pop() - op2);
break;
case '/':
op2 = pop();
if (op2 != 0.0)
push(pop() / op2);
else
printf("error: zero divisor\n");
break;